Skip to content

feat: add executable flag to pixi run#5253

Merged
ruben-arts merged 11 commits intoprefix-dev:mainfrom
kajal-jotwani:feat/run-executable-flag
Jan 26, 2026
Merged

feat: add executable flag to pixi run#5253
ruben-arts merged 11 commits intoprefix-dev:mainfrom
kajal-jotwani:feat/run-executable-flag

Conversation

@kajal-jotwani
Copy link
Contributor

@kajal-jotwani kajal-jotwani commented Jan 9, 2026

Description

Adds a --executable (-x) flag to pixi run to allow running executables even when a task with the same name exists.

Fixes #5128

How Has This Been Tested?

AI Disclosure

  • This PR contains AI-generated content.
    • I have tested any AI-generated content in my PR.
    • I take responsibility for any AI-generated content in my PR.

Tools: {e.g., Claude, Codex, GitHub Copilot, ChatGPT, etc.}

Checklist:

  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • I have added sufficient tests to cover my changes.
  • I have verified that changes that would impact the JSON schema have been made in schema/model.py.

.or(Some(Platform::current())),
);
let task_graph = TaskGraph::from_cmd_args(&project, &search_env, args.task, false)
let task_graph = TaskGraph::from_cmd_args(&project, &search_env, args.task, false, false)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a bit of an anti-pattern. If we have multiple booleans as arguments it becomes hard to distinguish what the false indicates. Instead its good practice to introduce an enum. E.g. PreferExecutable with variants like Always, Never, IfNoTask or something along those lines.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the suggestion! I've updated the implementation to use a PreferExecutable enum with Never and Always variants instead of bool. I didn't include an IfNoTask variant since that behavior is already the default when using PreferExecutable::Never the code naturally falls back to executing the command when no matching task is found.

@kajal-jotwani kajal-jotwani force-pushed the feat/run-executable-flag branch from e036167 to 93a8394 Compare January 16, 2026 20:20
@kajal-jotwani kajal-jotwani force-pushed the feat/run-executable-flag branch from 93a8394 to b267802 Compare January 16, 2026 20:31
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum PreferExecutable {
/// Always try to resolve as a Pixi task first (default behavior)
Never,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this correct? The implementation would suggest it falls back to executing an executable. With Never I would suspect that only tasks are run.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You’re right the current implementation falls back to executing it as an executable if no task exists. I’ll rename the enum to something clearer like TaskFirst to better reflect the actual behavior.

Comment on lines +53 to +54
/// Prefer running the command as an executable instead of a Pixi task
/// when both share the same name. Short: -x
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// Prefer running the command as an executable instead of a Pixi task
/// when both share the same name. Short: -x
/// Execute command without matching with a task name.
///
/// Usefull when a task name and an executable have the same name.

I feel that "prefer" sends a signal that it might still use tasks. But IIUC it will not try any task logic anymore.

Comment on lines +46 to +59
/// Controls whether to prefer resolving commands as executables over Pixi tasks
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum PreferExecutable {
/// Try to resolve as a Pixi task first, fall back to executable if no task found (default)
TaskFirst,
/// Always treat as an executable, skip task resolution
Always,
}

impl Default for PreferExecutable {
fn default() -> Self {
Self::TaskFirst
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// Controls whether to prefer resolving commands as executables over Pixi tasks
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum PreferExecutable {
/// Try to resolve as a Pixi task first, fall back to executable if no task found (default)
TaskFirst,
/// Always treat as an executable, skip task resolution
Always,
}
impl Default for PreferExecutable {
fn default() -> Self {
Self::TaskFirst
}
}
/// Controls whether to prefer resolving commands as executables over Pixi tasks
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub enum PreferExecutable {
/// Try to resolve as a Pixi task first, fall back to executable if no task found
#[default]
TaskFirst,
/// Always treat as an executable, skip task resolution
Always,
}

Rust (>1.62) has the ability to use the default derive so you don't have to write the default implementation yourself. We try to use this as much as possible

&search_envs,
run_args.iter().map(|arg| arg.to_string()).collect(),
skip_deps,
PreferExecutable::TaskFirst,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be good to add a test to check if the logic keeps working when you set it to always.

@kajal-jotwani
Copy link
Contributor Author

@ruben-arts thanks for the review! I have addressed all the comments.

Copy link
Contributor

@ruben-arts ruben-arts left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you! It works for me now!

@ruben-arts
Copy link
Contributor

As all @baszalmstra 's reviews are processed I'm merging this in.

@ruben-arts ruben-arts merged commit a5a98dc into prefix-dev:main Jan 26, 2026
40 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

For pixi run to use executable instead of task with --executable

3 participants